home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
sharewar
/
FFE
/
GRAPH.SWG
/
0063_HIPS to ICC Converter Source.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-05-11
|
5KB
|
142 lines
/*
*NAME
* hipstoicc - convert hips file to icc (suitable for the kodak printer)
*USAGE
* hipstoicc <in >out
*DESCRIPTION
* Converts a hips file to an icc file which is suitable for the
* kodak XL7700 (true color and gray scale printer).
*
* Hipstoicc handles only one frame.
*
* The format for the output file is a monochrome ICC file,
* padded to 8-pixel in the column or x direction.
*
* The format for the "ICC" header is:
*
* Magic Number (5965600) 4 bytes
* Header Length 4 bytes
* Extraneous data (Header Length -4) bytes
* Image File header length 4 bytes
* Header + data length 4 bytes
* Logical File Name 16 bytes
* File Type (7) 4 bytes
* Extraneous data 8 bytes
* Image X Size 4 bytes
* Image Y Size 4 bytes
* Extraneous data 12 bytes
* Plane Count 4 bytes
* Extraneous data 8 bytes
* Extraneous data n bytes
* RED DATA (X_SIZE * Y_SIZE bytes)
* GREEN DATA (X_SIZE * Y_SIZE bytes) if needed
* BLUE DATA (X_SIZE * Y_SIZE bytes) if needed
*
*
* -Nancy Johnston, LBL - 24 Aug. 1990
*/
#include "hipl_format.h"
#include <stdio.h>
#include <time.h> /* time defines */
#define STDOUT 1
/* input image declarations */
unsigned char *start_in_image_buf_byte, *in_image_byte;
int in_image_size_bytes ;
int num_rows, num_cols, num_frames, image_size;
long int x_col_pad;
char *out_line;
long int header[128]; /* file header buffer */
long int clock;
struct tm *date;
int frame_num = 1;
char *Progname;
/*int out_fp;*/
main(argc,argv)
int argc;
char **argv;
{
struct header hd;
int i, j;
Progname = strsave(*argv);
read_header(&hd);
if(hd.pixel_format != PFBYTE)
perr("pixel format must be bytes");
num_rows = hd.rows;
num_cols = hd.cols;
x_col_pad = (num_cols + 7) & 0xfffffff8L;
/* allocated storage for one scan line */
out_line = (char *)calloc (x_col_pad, sizeof(char));
if (!out_line)
{
printf (" Could not allocated storage for scan line\n");
return (-1);
}
/* load outputted scanline with white */
for (i = 0; i < x_col_pad; ++i) out_line[i] = 255;
/* compute size of the image being read in */
image_size = num_rows * num_cols;
num_frames = hd.num_frame;
/****** INITIALIZATION ******/
for (i = 0; i < 128; i++) header[i] = 0;
clock = time((long *)0);
date = localtime(&clock);
header[0] = 5965600; /* magic number */
header[1] = 60; /* header length */
header[2] = 0; /* no H/W version */
header[3] = 0; /* no S/W version */
/* creation date */
header[4] = (((long)date->tm_year << 24) & 0xff000000L) +
(((long)(date->tm_mon + 1) << 16) & 0x00ff0000L) +
(((long)date->tm_mday << 8) & 0x0000ff00L) +
((long)date->tm_hour & 0x000000ffL);
header[5] = (((long)date->tm_min << 24) & 0xff000000L) +
(((long)date->tm_sec << 16) & 0x00ff0000L);
header[6] = 0; /* no update date */
header[7] = 0;
header[8] = 0x64656d6fL; /* user name ("demo") */
header[16] = 80; /* subfile header length */
header[17] = header[16] + (x_col_pad * num_rows); /* subfile length */
header[22] = 7; /* file type */
header[25] = num_cols; /* image x size */
header[26] = num_rows; /* image y size */
header[29] = 1; /* gray scale */
header[30] = 1; /* plane count */
write(STDOUT,header,144);
/****** READ IN HIPS FILE ******/
start_in_image_buf_byte = (unsigned char*) halloc(image_size, sizeof (char));
in_image_byte = start_in_image_buf_byte;
in_image_size_bytes = image_size * (sizeof(char));
if ((i = pread(0, start_in_image_buf_byte, in_image_size_bytes))
!= in_image_size_bytes)
perr("Unexpected end-of-file in frame number %d. %d bytes \
read for this frame.", frame_num, i);
in_image_byte = start_in_image_buf_byte; /* set pointer to start of image */
/****** write out each row padding to 8 bits because thats what
icc or kodak wants ******/
for (i=0; i < num_rows; ++i)
{
for (j = 0; j < num_cols; j++)
out_line[j] = *in_image_byte++;
write (STDOUT, out_line, x_col_pad);
}
}